package com.feihong.yw189.paidan.tools;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;

import com.feihong.yw189.activity.MyActivityManager;
import com.feihong.yw189.activity.denglu.DengLuActivity;
import com.feihong.yw189.http.RefreshToken;
import com.feihong.yw189.utils.ThreadPoolManager;
import com.feihong.yw189.utils.UserLoginInfo;

import java.lang.ref.SoftReference;
import java.util.Stack;

/**
 * Created by yucheng on 2018/5/9.
 */

public class RefReshToken {

    private static boolean refreshResult;

    public static Boolean refshToken() {
        ThreadPoolManager.getInstance().execute(new Runnable() {
            @Override
            public void run() {
                refreshResult = RefreshToken.getInstance().postRequestGetToken();
            }
        });
        return refreshResult;
    }

    public static void exitLogin() {
        UserLoginInfo.getUserLoginInfoInstance().updateUserToken("");
        Stack<SoftReference<Activity>> stack = MyActivityManager.mActivites;
        if (stack != null && stack.size() > 0) {
            Activity activity = stack.lastElement().get();
            Intent intent = new Intent(activity, DengLuActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivity(intent);
        }
    }
}
